function distance = affinitymodel(  framenode1,   framenode2)
    distance = zeros(framenode1.detectornum, framenode2.detectornum);
    
    sig_position = 1;
    sig_scale = 1;
    
    for j = 1:framenode1.detectornum
         for k = 1:framenode2.detectornum
             
              distance(j,k) = - log(  sqrt(sum(framenode1.detectors(j).appearance.*framenode2.detectors(k).appearance))  );
              
              location_pre = framenode1.detectors(j).location + [framenode1.detectors(j).height/2, framenode1.detectors(j).width/2];
              location_now = framenode2.detectors(k).location + [framenode2.detectors(k).height/2, framenode2.detectors(k).width/2];
              
              
              distance(j,k) = distance(j,k) - log(sig_position) + sum( (location_pre - location_now).^2 )/(2 * sig_position);
              
              distance(j,k) = distance(j,k) - log(sig_scale) + (framenode1.detectors(j).scale - framenode2.detectors(k).scale)^2/(2*sig_scale);
              
         end
   end
end